ActiveReports 9 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Section Report Walkthroughs > Parameters > Using Parameters in SubReports |
Using parameters in SubReport, you can connect a SubReport to the parent report. By setting the parameter on the field that binds the parent report to SubReport, the parent report passes the data to display in SubReport through a parameter. This walkthrough illustrates the method to link the main report with a SubReport using parameters.
This walkthrough is split up into the following activities:
Note: This walkthrough uses tables from the NorthWind database. By default, in ActiveReports, the NWind.mdb file is located in the [User Documents folder]\ComponentOne Samples\ActiveReports 9\Data folder. |
Caution: SubReports do not render PageHeader and PageFooter sections. |
When you complete this walkthrough you get a layout that looks similar to the following:
To add an ActiveReport to the Visual Studio project
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the Parent Report (rptParent) to a data source
SQL Query |
Copy Code
|
---|---|
Select * from suppliers order by country |
To connect the subreport (rptChild) to a data source using parameter
SQL Query |
Copy Code
|
---|---|
SELECT * FROM products INNER JOIN categories ON products.categoryid = categories.categoryid WHERE Products.SupplierID = <%SupplierID%> |
To create a layout for the Parent Report (rptParent)
Property Name | Property Value |
---|---|
Name | ghSuppliers |
DataField | Country |
Property Name | Property Value |
---|---|
DataField | Country |
Name | txtCountry |
Text | Country |
Location | 0, 0 |
Font | Arial, 13pt, style=Bold |
TextBox1
Property Name | Property Value |
---|---|
DataField | CompanyName |
Name | txtCompanyName |
Text | Company Name |
Location | 0.0625, 0.0625 |
Size | 2.25, 0.2 in |
Style | background-color: Silver; font-weight: bold |
TextBox2
Property Name | Property Value |
---|---|
DataField | ContactName |
Name | txtContactName |
Text | Contact Name |
Location | 2.312, 0.0625 |
Size | 1.708, 0.2 in |
Style | background-color: Silver; font-weight: bold |
TextBox3
Property Name | Property Value |
---|---|
DataField | Phone |
Name | txtPhone |
Text | Phone |
Location | 4.562, 0.0625 |
Size | 1.542, 0.2 in |
Style | background-color: Silver; font-weight: bold |
SubReport
Property Name | Property Value |
---|---|
Name | Subreport1 |
ReportName | ProductName |
Location | 0.0625, 0.312 |
To create a layout for the SubReport (rptChild)
Property Name | Property Value |
---|---|
Name | ghProducts |
DataField | CategoryName |
Property Name | Property Value |
---|---|
DataField | CategoryName |
Name | txtCategoryName |
Text | Category Name |
Location | 0.0625, 0.0625 |
Size | 2.042, 0.2 in |
Style | color: Maroon; font-weight: bold |
Property Name | Property Value |
---|---|
DataField | ProductName |
Name | txtProductName |
Text | Product Name |
Location | 0.0625, 0.0625 |
Size | 1.99, 0.2 in |
Style | color: Red |
To connect the SubReport (rptChild) to the SubReport control in parent report (rptParent)
To write the code in Visual Basic
Visual Basic.NET code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
Dim rpt As rptChild |
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = New rptChild() |
To write the code in C#
C# code. Paste JUST ABOVE the ReportStart event. |
Copy Code
|
---|---|
private rptChild rpt; |
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
rpt = new rptChild(); |
To write the code in Visual Basic
Visual Basic.NET code. Paste INSIDE the Format event. |
Copy Code
|
---|---|
Me.SubReport1.Report = rpt |
To write the code in C#
C# code. Paste INSIDE the Format event. |
Copy Code
|
---|---|
this.subReport1.Report = rpt; |
To set the ShowParametersUI property of SubReport to False
To write the code in Visual Basic
Visual Basic.NET code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
Private Sub rptChild_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ReportStart
Me.ShowParameterUI = False
End Sub
|
To write the code in C#
C# code. Paste INSIDE the ReportStart event. |
Copy Code
|
---|---|
private void rptChild_ReportStart(object sender, System.EventArgs eArgs)
{
this.ShowParameterUI = false;
}
|
To view the report
OR